home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / mawk.zip / SYMTYPE.H < prev    next >
C/C++ Source or Header  |  1991-04-07  |  4KB  |  163 lines

  1.  
  2. /********************************************
  3. symtype.h
  4. copyright 1991, Michael D. Brennan
  5.  
  6. This is a source file for mawk, an implementation of
  7. the Awk programming language as defined in
  8. Aho, Kernighan and Weinberger, The AWK Programming Language,
  9. Addison-Wesley, 1988.
  10.  
  11. See the accompaning file, LIMITATIONS, for restrictions
  12. regarding modification and redistribution of this
  13. program in source or binary form.
  14. ********************************************/
  15.  
  16. /*$Log:    symtype.h,v $
  17.  * Revision 2.1  91/04/08  08:24:14  brennan
  18.  * VERSION 0.97
  19.  * 
  20. */
  21.  
  22. /* types related to symbols are defined here */
  23.  
  24. #ifndef  SYMTYPE_H
  25. #define  SYMTYPE_H
  26.  
  27.  
  28. /* struct to hold info about builtins */
  29. typedef struct {
  30. char *name ;
  31. PF_CP  fp ;  /* ptr to function that does the builtin */
  32. unsigned char min_args, max_args ; 
  33. /* info for parser to check correct number of arguments */
  34. } BI_REC ;
  35.  
  36. /*---------------------------
  37.    structures and types for arrays
  38.  *--------------------------*/
  39.  
  40. /* array hash nodes */
  41.  
  42. typedef  struct anode {
  43. struct anode *link ;
  44. STRING *sval ;
  45. CELL   *cp ;
  46. }  ANODE, **ARRAY ;
  47.  
  48. /* note ARRAY is a ptr to a hash table */
  49.  
  50. CELL *PROTO(array_find, (ARRAY,void *, int) ) ;
  51. int PROTO(array_test, (ARRAY, STRING *) ) ;
  52. INST *PROTO(array_loop, (INST *, CELL *, CELL *) ) ;
  53. void PROTO(array_delete, (ARRAY, STRING *) ) ;
  54. CELL *PROTO(array_cat, (CELL *, int) ) ;
  55. void PROTO(array_free, (ARRAY) ) ;
  56.  
  57. #define new_ARRAY() (ARRAY)memset(zmalloc(A_HASH_PRIME *\
  58.                         sizeof(ANODE*)), 0, A_HASH_PRIME*sizeof(ANODE*))
  59.  
  60. extern  ARRAY  Argv ;
  61.  
  62. /* for parsing  (i,j) in A  */
  63. typedef  struct {
  64. INST *start ;
  65. int cnt ;
  66. } ARG2_REC ;
  67.  
  68. /*------------------------
  69.   user defined functions
  70.   ------------------------*/
  71.  
  72. typedef  struct fblock {
  73. char *name ;
  74. INST *code  ;
  75. unsigned short nargs ;
  76. char *typev ;  /* array of size nargs holding types */
  77. } FBLOCK ;   /* function block */
  78.  
  79. void  PROTO(add_to_fdump_list, (FBLOCK *) ) ;
  80. void  PROTO( fdump, (void) ) ;
  81.  
  82. /*-------------------------
  83.   elements of the symbol table
  84.   -----------------------*/
  85.  
  86. #define  ST_NONE 0
  87. #define  ST_VAR   1
  88. #define  ST_KEYWORD   2
  89. #define  ST_BUILTIN 3 /* a pointer to a builtin record */
  90. #define  ST_ARRAY   4 /* a void * ptr to a hash table */
  91. #define  ST_FIELD   5  /* a cell ptr to a field */
  92. #define  ST_FUNCT   6
  93. #define  ST_LENGTH  7  /* length is special */
  94. #define  ST_LOCAL_NONE  8
  95. #define  ST_LOCAL_VAR   9
  96. #define  ST_LOCAL_ARRAY 10
  97.  
  98. #define  is_local(stp)   ((stp)->type>=ST_LOCAL_NONE)
  99.  
  100. typedef  struct {
  101. char *name ;
  102. char type ;
  103. unsigned char offset ;  /* offset in stack frame for local vars */
  104. union {
  105. CELL *cp ;
  106. int  kw ;
  107. PF_CP fp ;
  108. BI_REC *bip ;
  109. ARRAY  array ; 
  110. FBLOCK  *fbp ;
  111. } stval ;
  112. }  SYMTAB ;
  113.  
  114.  
  115. /*****************************
  116.  structures for type checking function calls
  117.  ******************************/
  118.  
  119. typedef  struct ca_rec {
  120. struct ca_rec  *link ;
  121. short type ;
  122. short arg_num ;  /* position in callee's stack */
  123. /*---------  this data only set if we'll  need to patch -------*/
  124. /* happens if argument is an ID or type ST_NONE or ST_LOCAL_NONE */
  125.  
  126. int call_offset ;
  127. /* where the type is stored */
  128. SYMTAB  *sym_p ;  /* if type is ST_NONE  */
  129. char *type_p ;  /* if type  is ST_LOCAL_NONE */
  130. }  CA_REC  ; /* call argument record */
  131.  
  132. /* type field of CA_REC matches with ST_ types */
  133. #define   CA_EXPR       ST_LOCAL_VAR
  134. #define   CA_ARRAY      ST_LOCAL_ARRAY
  135.  
  136. typedef  struct fcall {
  137. struct fcall *link ;
  138. FBLOCK  *callee ;
  139. short   call_scope ;
  140. FBLOCK  *call ;  /* only used if call_scope == SCOPE_FUNCT  */
  141. INST    *call_start ; /* computed later as code may be moved */
  142. CA_REC  *arg_list ;
  143. short   arg_cnt_checked ;
  144. unsigned line_no ; /* for error messages */
  145. } FCALL_REC ;
  146.  
  147. extern  FCALL_REC  *resolve_list ;
  148.  
  149. void PROTO(resolve_fcalls, (void) ) ;
  150. void PROTO(check_fcall, (FBLOCK*,int,FBLOCK*,CA_REC*,unsigned) ) ;
  151.  
  152. /* hash.c */
  153. unsigned  PROTO( hash, (char *) ) ;
  154. SYMTAB *PROTO( insert, (char *) ) ;
  155. SYMTAB *PROTO( find, (char *) ) ;
  156. SYMTAB *PROTO( save_id, (char *) ) ;
  157. void    PROTO( restore_ids, (void) ) ;
  158.  
  159. /* error.c */
  160. void  PROTO(type_error, (SYMTAB *) ) ;
  161.  
  162. #endif  /* SYMTYPE_H */
  163.